#include "stdafx.h"
#include "../../resource.h"
//#include "AutoHideBar.h"
//#include "gncase2.h"


#include "mybar.h"
/////////////////////////////////////////////////////////////////////////////
// CMyBar

CMyBar::CMyBar()
{
}

CMyBar::~CMyBar()
{
}

BEGIN_MESSAGE_MAP(CMyBar, CPinDockBar)
	//{{AFX_MSG_MAP(CMyBar)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_NOTIFY(TCN_SELCHANGE, 102, OnTabSelChange)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


void CMyBar::AddToDrawBar(CAutoHideBar * pDrawBar)
{
	CRect rt;
	m_Tree.GetClientRect(&rt);
	m_Tree.ShowWindow(SW_SHOW);
	pDrawBar->AddButton(" Tree View ", DRAWBTNSTYLE_GROUP | DRAWBTNSTYLE_SELECT, &m_Tree, &m_tabctrl, &rt, this, 0);
	
	m_List.ShowWindow(SW_SHOW);
	pDrawBar->AddButton(" List View ", DRAWBTNSTYLE_GROUP, &m_List, &m_tabctrl, &rt, this, 1);

	m_Edit.ShowWindow(SW_SHOW);
	pDrawBar->AddButton(" Edit View ", DRAWBTNSTYLE_GROUP, &m_Edit, &m_tabctrl, &rt, this, 2);

};

void CMyBar::RemoveFromDrawBar(CAutoHideBar * pDrawBar)
{
	CRect rt;
	pDrawBar->RemoveButton(&m_Tree);
	pDrawBar->RemoveButton(&m_List);
	pDrawBar->RemoveButton(&m_Edit);
	pDrawBar->Shrink();
	pDrawBar->CalcLayout();
	pDrawBar->Invalidate();
	GetParentFrame()->ShowControlBar(this, TRUE, FALSE);

	m_tabctrl.GetWindowRect(&rt);
	m_tabctrl.SetCurSel(0);
	m_Tree.ShowWindow(SW_SHOW);
	m_List.ShowWindow(SW_HIDE);
	m_Edit.ShowWindow(SW_HIDE);

	GetClientRect(&rt);
	int cx = rt.Width();
	int cy = rt.Height();
	// TODO: Add your message handler code here
	int bottom = IsFloating() ? cy - 14 : cy - 18;

	m_tabctrl.MoveWindow(7, 7, cx - 14, bottom);
	CRect rect, rect1, rect2, rect3;
	m_tabctrl.GetClientRect(&rect);
	m_tabctrl.GetItemRect(0, &rect1);
	m_tabctrl.GetItemRect(1, &rect2);
	m_tabctrl.GetItemRect(2, &rect3);
	m_Tree.MoveWindow(9,9, rect.right - 18, rect.bottom - rect1.Height() - 9 - 9);
	m_List.MoveWindow(9,9, rect.right - 18, rect.bottom - rect2.Height() - 9 - 9);
	m_Edit.MoveWindow(9,9, rect.right - 18, rect.bottom - rect3.Height() - 9 - 9);


};

/////////////////////////////////////////////////////////////////////////////
// CMyBar message handlers

int CMyBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CPinDockBar::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	CRect rect;
	m_tabctrl.Create(WS_VISIBLE | WS_CHILD | TCS_BOTTOM  , 
		rect, this, 102);
	
	m_ImgList.Create(IDB_TAB, 16, 1, RGB(255,0,255));

	m_tabctrl.SetImageList(&m_ImgList);
	
	// set "normal" GUI-font
	CFont *font = CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
	m_tabctrl.SetFont(font);
	DWORD dwSTyle = TCS_RAGGEDRIGHT;
	m_Tree.Create(WS_VISIBLE | WS_BORDER | WS_CHILD | TVS_HASBUTTONS|TVS_LINESATROOT|
		TVS_HASLINES|TVS_SHOWSELALWAYS , rect, &m_tabctrl, 201);
	m_List.Create(WS_BORDER | WS_CHILD |LVS_REPORT | LVS_SINGLESEL,
		rect, &m_tabctrl, 202);
	m_Edit.Create(WS_BORDER | WS_CHILD | ES_MULTILINE | ES_AUTOHSCROLL,
		rect, &m_tabctrl, 203);
	
	HTREEITEM hRootItem = m_Tree.InsertItem("PLan",0,0);
	TC_ITEM tci;
	tci.mask = TCIF_TEXT | TCIF_IMAGE;
	tci.pszText = (LPTSTR)(LPCTSTR)"Tree";
	tci.iImage = 0;
	m_tabctrl.InsertItem(0, &tci);

	tci.mask = TCIF_TEXT | TCIF_IMAGE;
	tci.pszText = (LPTSTR)(LPCTSTR)"List";
	tci.iImage = 1;
	m_tabctrl.InsertItem(1, &tci);

	tci.mask = TCIF_TEXT | TCIF_IMAGE;
	tci.pszText = (LPTSTR)(LPCTSTR)"Edit";
	tci.iImage = 2;
	m_tabctrl.InsertItem(2, &tci);

	//	m_ImgList.Create(IDB_BITMAP1, 16, 7, RGB(255, 255, 255));
	m_Tree.SetImageList(&m_ImgList, TVSIL_NORMAL);
	//FillSector();
	m_tabctrl.SetCurSel(0);


	return 0;
}

void CMyBar::OnSize(UINT nType, int cx, int cy) 
{
	CPinDockBar::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	int bottom = (IsFloating() || IsFloating()) ? cy - 7 : cy - 9;

	m_tabctrl.MoveWindow(7, 7, cx - 14, bottom);
	CRect rect, rect1, rect2, rect3;
	m_tabctrl.GetClientRect(&rect);
	m_tabctrl.GetItemRect(0, &rect1);
	m_tabctrl.GetItemRect(1, &rect2);
	m_tabctrl.GetItemRect(2, &rect3);
	m_Tree.MoveWindow(9,9, rect.right - 18, rect.bottom - rect1.Height() - 9 - 9);
	m_List.MoveWindow(9,9, rect.right - 18, rect.bottom - rect2.Height() - 9 - 9);
	m_Edit.MoveWindow(9,9, rect.right - 18, rect.bottom - rect3.Height() - 9 - 9);


}

afx_msg void CMyBar::OnTabSelChange(NMHDR* pNMHDR, LRESULT* pResult)
{	
	int Sel = m_tabctrl.GetCurSel();
	m_List.ShowWindow(Sel == 1?SW_SHOW:SW_HIDE);
	m_Tree.ShowWindow(Sel == 0?SW_SHOW:SW_HIDE);
	m_Edit.ShowWindow(Sel == 2?SW_SHOW:SW_HIDE);
	//m_tabctrl.SetCurSel(Sel);

}


/////////////////////////////////////////////////////////////////////////////
// CMyBar2

CMyBar2::CMyBar2()
{
}

CMyBar2::~CMyBar2()
{
}

void CMyBar2::AddToDrawBar(CAutoHideBar * pDrawBar)
{
	CRect rt;
	GetClientRect(&rt);
	CString szStr;
	GetWindowText(szStr);
	pDrawBar->AddButton(szStr, DRAWBTNSTYLE_BTN, &m_List, this, &rt, this, 0);
	
};

void CMyBar2::RemoveFromDrawBar(CAutoHideBar * pDrawBar)
{
	CRect rect;
	pDrawBar->RemoveButton(&m_List);
	pDrawBar->Shrink();
	pDrawBar->CalcLayout();
	pDrawBar->Invalidate();
	GetParentFrame()->ShowControlBar(this, TRUE, FALSE);

	GetClientRect(&rect);
	m_List.MoveWindow(9,9, rect.Width() - 18, rect.Height() - 9 - 9);



};

BEGIN_MESSAGE_MAP(CMyBar2, CPinDockBar)
	//{{AFX_MSG_MAP(CMyBar)
	ON_WM_CREATE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CMyBar message handlers

int CMyBar2::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CSizingControlBarG::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	CRect rect;
	m_List.Create(WS_VISIBLE | WS_BORDER | WS_CHILD ,
		rect, this, 202);

	return 0;
}

void CMyBar2::OnSize(UINT nType, int cx, int cy) 
{
	CSizingControlBarG::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	m_List.MoveWindow(9,9, cx - 18, cy - 9 - 9);


}

